package main

import (
	"flag"
	"fmt"
	"iron_man_comm/src/goroslib"
	"iron_man_comm/src/goroslib/dns"
	"iron_man_comm/src/msg/common_msg"
	"os"
	"time"
)

func main() {
	controlType := flag.Uint("t", 0, "uint8 TypeCalc=0,\nuint8 TypeNormal=1")
	cmd := flag.Bool("c", true, "")
	ip := flag.String("ip", "127.0.0.1", "目标ip")
	flag.Parse()

	fmt.Printf("control type: %d, cmd: %v, ip: %s\n", *controlType, *cmd, *ip)

	dns.GetDNSCacheInterface().UpdateDNSMapping("rk3562-buildroot", *ip)
	node, err := goroslib.NewNode(goroslib.NodeConf{
		Name:          fmt.Sprintf("mcu_sleep_%d", time.Now().UnixMilli()),
		MasterAddress: fmt.Sprintf("%s:11311", *ip),
	})
	if err != nil {
		fmt.Println("create node fail, err: %s", err.Error())
		return
	}
	defer node.Close()

	publisher, err := goroslib.NewPublisher(goroslib.PublisherConf{
		Node:  node,
		Topic: "/plat/camera/ir/cmd",
		Msg:   &common_msg.CameraControl{},
		Latch: true,
	})
	if err != nil {
		fmt.Println("create publish fail, err: %s", err.Error())
		return
	}
	defer publisher.Close()

	publisher.Write(&common_msg.CameraControl{
		Type: uint8(*controlType),
		Cmd:  *cmd,
	})

	c := make(chan os.Signal, 1)
	_ = <-c
}
